package com.example.book.model;

import com.example.book.enums.ResutlCode;
import lombok.Data;

import java.util.Date;

@Data
public class Result {
    /**
     * 业务状态码
     * 0 - 成功
     * -1 - 失败
     * -2 - 未登入
     */
    private ResutlCode code;
    /**
     * 错误信息
     */
    private String errMeg;
    private Object data;

    public static Result success(Object date) {
        Result result = new Result();
        result.setCode(ResutlCode.SUCCESS);
        result.setErrMeg("");
        result.setData(date);
        return result;
    }
    public static Result fail(String errMeg) {
        Result result = new Result();
        result.setCode(ResutlCode.FATL);
        result.setErrMeg(errMeg);
        result.setData(null);
        return result;
    }
    public static Result fail(String errMeg,Date date) {
        Result result = new Result();
        result.setCode(ResutlCode.FATL);
        result.setErrMeg(errMeg);
        result.setData(date);
        return result;
    }
    public static Result unlogin() {
        Result result = new Result();
        result.setCode(ResutlCode.UNLOGIN);
        result.setErrMeg("用户未登录");
        result.setData(null);
        return result;
    }



}
